package com.mall.service.eshop;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.eshop.EshopUserInfoService;
import com.mall.custom.dao.read.EshopUserInfoReadMapper;
import com.mall.custom.dao.write.EshopUserInfoWriteMapper;
import com.mall.pojo.EshopUserInfo;
import com.mall.pojo.EshopUserInfoExample;
import com.mall.pojo.EshopUserInfoExample.Criteria;
import com.mall.query.Page;
import com.mall.query.eshop.EshopUserQuery;

@Service
public class EshopUserInfoServiceImpl implements EshopUserInfoService {
	// private static final Logger log =
	// LoggerFactory.getLogger(SellerInfoServiceImpl.class);
	@Autowired
	private EshopUserInfoReadMapper EshopUserInfoReadMapper;
	@Autowired
	private EshopUserInfoWriteMapper EshopUserInfoWriteMapper;

	/**
	 * 获得出售店铺人的信息列表
	 * 
	 * @param sellerInfoExample
	 * @return
	 */
	@Override
	public List<EshopUserInfo> getEshopUserInfoListBySellerInfoExample(EshopUserInfoExample sellerInfoExample) {
		// TODO Auto-generated method stub
		return this.EshopUserInfoReadMapper.selectByExample(sellerInfoExample);
	}

	/**
	 * 修改售铺者信息
	 * 
	 * @param sellerInfo
	 * @return
	 */
	@Override
	public int modifyEshopUserInfoBySellerInfo(EshopUserInfo eshopUserInfo) {
		eshopUserInfo.setGmtModify(new Date());
		return this.EshopUserInfoWriteMapper.updateByPrimaryKey(eshopUserInfo);
	}

	/**
	 * 添加售铺者信息
	 * 
	 * @param sellerInfo
	 * @return
	 */
	@Override
	public int insertEshopUserInfoBySellerInfo(EshopUserInfo eshopUserInfo) {
		eshopUserInfo.setGmtCreate(new Date());
		eshopUserInfo.setGmtModify(new Date());
		return this.EshopUserInfoWriteMapper.insert(eshopUserInfo);
	}

	/**
	 * 通过id获得售铺者信息
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public EshopUserInfo getEshopUserInfoBySellerInfoId(Long id) {
		// TODO Auto-generated method stub
		return this.EshopUserInfoReadMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<EshopUserInfo> getEshopUserInfoListBySellerInfoByQuery(EshopUserQuery eshopUserQuery, Page page) {
		EshopUserInfoExample sellerInfoExample = new EshopUserInfoExample();
		if (page != null) {
			sellerInfoExample.setLimit(page.getLength());
			sellerInfoExample.setStart(page.getBegin());
		}
		sellerInfoExample.setOrderByClause(eshopUserQuery.getOrderby());
		Criteria criteria = sellerInfoExample.createCriteria();
		if (eshopUserQuery.getType() != null) {
			criteria.andTypeEqualTo(eshopUserQuery.getType());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getName())){
			criteria.andNameLike(eshopUserQuery.getName());
		}
		if(eshopUserQuery.getQq() != null){
			criteria.andQqEqualTo(eshopUserQuery.getQq());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getPhone())){
			criteria.andPhoneLike(eshopUserQuery.getPhone());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getWangwang())){
			criteria.andWangwangLike(eshopUserQuery.getWangwang());
		}
		criteria.andCommOnlyKeyEqualTo(eshopUserQuery.getOnlyKey());
		return this.getEshopUserInfoListBySellerInfoExample(sellerInfoExample);
	}

	@Override
	public Integer getEshopUserInfoCountByExample(EshopUserInfoExample example) {
		return this.EshopUserInfoReadMapper.countByExample(example);
	}

	@Override
	public int getEshopUserInfoCountByQuery(EshopUserQuery eshopUserQuery) {
		EshopUserInfoExample sellerInfoExample = new EshopUserInfoExample();
		sellerInfoExample.setOrderByClause(eshopUserQuery.getOrderby());
		Criteria criteria = sellerInfoExample.createCriteria();
		if (eshopUserQuery.getType() != null) {
			criteria.andTypeEqualTo(eshopUserQuery.getType());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getName())){
			criteria.andNameLike(eshopUserQuery.getName());
		}
		if(eshopUserQuery.getQq() != null){
			criteria.andQqEqualTo(eshopUserQuery.getQq());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getPhone())){
			criteria.andPhoneLike(eshopUserQuery.getPhone());
		}
		if(StringUtils.isNotBlank(eshopUserQuery.getWangwang())){
			criteria.andWangwangLike(eshopUserQuery.getWangwang());
		}
		criteria.andCommOnlyKeyEqualTo(eshopUserQuery.getOnlyKey());
		return this.EshopUserInfoReadMapper.countByExample(sellerInfoExample);
	}

}
